package thread;

public class DaemonThreadDemo {
    public static void main(String[] args) {
        Thread rose = new Thread(){
           public void run(){
               for (int i = 0; i < 5; i++) {
                   System.out.println("rose:let me go!");
                   try {
                       Thread.sleep(1000);
                   } catch (InterruptedException e) {
                   }
               }
               System.out.println("rose:啊啊啊啊啊啊...");
               System.out.println("噗通！");
           }
        };
        Thread jack = new Thread(){
            public void run(){
                while (true){
                    System.out.println("jack:你跳，俺也跳！");
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                    }
                }
            }
        };
        rose.start();
        //设置守护线程这个工作必须在线程启动前进行
        jack.setDaemon(true);//将jack线程设置为守护线程
        jack.start();

        while (true);
    }
}
